package test1;

import java.util.Arrays;

public class TestSort {
    public static void insertSort(int[] array) {
        if(array==null) return;
        for (int i = 0; i < array.length; i++) {
            int tmp=array[i];
            int j=i-1;
            for(;j>=0;j--){
                if(tmp<array[j]){
                    array[j+1]=array[j];
                }
                else {
                    break;
                }
            }
            array[j+1]=tmp;
        }
    }
    public static void shell(int[] array,int gap) {
        if(array==null) return;
        for (int i = gap; i < array.length; i++) {
            int tmp=array[i];
            int j=i-gap;
            for(;j>=0;j--){
                if(tmp<array[j]){
                    array[j+gap]=array[j];
                }
                else {
                    break;
                }
            }
            array[j+gap]=tmp;
        }
    }
    public static void shellSort(int[] array){
        int length= array.length-1;
        while (length>0){
            shell(array,length);
            length=length/2;
        }
        shell(array,1);
    }
    public static void main(String[] args) {
        int[] array = {6,2,1,7,5};
        System.out.println(Arrays.toString(array));
        shellSort(array);
        System.out.println(Arrays.toString(array));
    }
}
